package com.sui.bigdata.rtcadmin.repository.model;

import com.sui.bigdata.rtcadmin.constant.AppConstant;
import com.sui.bigdata.rtcadmin.model.dto.SparkAppDto;
import io.netty.util.internal.StringUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.type.Alias;

import java.util.Date;


/**
 * @Author: TingWuHuang
 * @Date: 2020/5/6 15:30
 * @description
 */
@Data
@Alias("SparkApp")
@Accessors(chain = true)
public class SparkApp {
    private String id;
    private String appName;
    private String appId;
    private String appResource;
    /**
     * 任务类型：0：Spark批任务，1：SparkStreaming，2：thriftServer
     */
    private String appStyle;
    private String mainClass;
    private String appStatus;
    private String appArgs;
    private String developer;
    private String alarmGroupPhone;
    private String queue;
    private String trackingUrl;
    private String model;
    private String executorMemory;
    private String driverMemory;
    private String executorCores;
    private String numExecutors;
    private String extendParam;
    private String driverJavaOption;
    private String executorJavaOption;
    private String remarks;
    private Date createTime;
    private Date updateTime;

    public static SparkApp buildSparkApp(SparkAppDto sparkAppDto){
        if(sparkAppDto == null){
            return null;
        }
        return new SparkApp()
                .setAppName(sparkAppDto.getAppName())
                .setAppId(sparkAppDto.getAppId())
                .setAppResource(sparkAppDto.getAppResource())
                .setAppStyle(StringUtils.isEmpty(sparkAppDto.getAppStyle())
                        ? AppConstant.SPARK_APPLICATION_BATCH : sparkAppDto.getAppStyle())
                .setMainClass(sparkAppDto.getMainClass())
                .setAppStatus(sparkAppDto.getAppStatus())
                .setAppArgs(StringUtils.isEmpty(sparkAppDto.getAppArgs()) ? "" :sparkAppDto.getAppArgs())
                .setDeveloper(StringUtils.isEmpty(sparkAppDto.getDeveloper()) ? "" : sparkAppDto.getDeveloper())
                .setAlarmGroupPhone(StringUtils.isEmpty(sparkAppDto.getAlarmGroupPhone())
                        ? "" : sparkAppDto.getAlarmGroupPhone())
                .setQueue(StringUtils.isEmpty(sparkAppDto.getQueue())
                        ? AppConstant.DEFAULT_QUEUE : sparkAppDto.getQueue())
                .setTrackingUrl(sparkAppDto.getTrackingUrl())
                .setModel(StringUtils.isEmpty(sparkAppDto.getModel())
                        ? AppConstant.SPARK_CLUSTER_MODEL : sparkAppDto.getModel())
                .setExecutorMemory(StringUtils.isEmpty(sparkAppDto.getExecutorMemory())
                        ? AppConstant.SPARK_EXECUTOR_MEMORY_DEFAULT :sparkAppDto.getExecutorMemory())
                .setDriverMemory(StringUtils.isEmpty(sparkAppDto.getDriverMemory())
                        ? AppConstant.SPARK_DRIVER_MEMORY_DEFAULT : sparkAppDto.getDriverMemory())
                .setExecutorCores(StringUtils.isEmpty(sparkAppDto.getExecutorCores())
                        ? AppConstant.SPARK_EXECUTOR_CORES_DEFAULT : sparkAppDto.getExecutorCores())
                .setNumExecutors(sparkAppDto.getNumExecutors())
                .setExtendParam(sparkAppDto.getExtendParam())
                .setDriverJavaOption(sparkAppDto.getDriverJavaOption())
                .setExecutorJavaOption(sparkAppDto.getExecutorJavaOption())
                .setRemarks(sparkAppDto.getRemarks());


    }

    @Override
    public String toString() {
        return "SparkAppDto{" +
                "id='" + id + '\'' +
                ", appName='" + appName + '\'' +
                ", appId='" + appId + '\'' +
                ", appResource='" + appResource + '\'' +
                ", appStyle='" + appStyle + '\'' +
                ", mainClass='" + mainClass + '\'' +
                ", appStatus='" + appStatus + '\'' +
                ", appArgs='" + appArgs + '\'' +
                ", developer='" + developer + '\'' +
                ", alarmGroupPhone='" + alarmGroupPhone + '\'' +
                ", queue='" + queue + '\'' +
                ", trackingUrl='" + trackingUrl + '\'' +
                ", model='" + model + '\'' +
                ", executorMemory='" + executorMemory + '\'' +
                ", driverMemory='" + driverMemory + '\'' +
                ", executorCores='" + executorCores + '\'' +
                ", numExecutors='" + numExecutors + '\'' +
                ", extendParam='" + extendParam + '\'' +
                ", driverJavaOption='" + driverJavaOption + '\'' +
                ", executorJavaOption='" + executorJavaOption + '\'' +
                ", remarks='" + remarks + '\'' +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
}
